# Scripts for analyzing spectrum.dat files
from numpy import *

def rspec(specfile):
    fid = open(specfile,'r')
    s = fid.readline()
    ks = array([double(sk) for sk in s.split()])
    s = fid.readline()
    nk = array([int(round(float(sn))) for sn in s.split()])
    print 'There are {:d} k-shells'.format(len(ks))
    ns = 21
    data = loadtxt(specfile,skiprows=2)
    vx = data[0::ns,1:].mean(axis=0)
    vy = data[1::ns,1:].mean(axis=0)
    vz = data[2::ns,1:].mean(axis=0)
    bx = data[3::ns,1:].mean(axis=0)
    by = data[4::ns,1:].mean(axis=0)
    bz = data[5::ns,1:].mean(axis=0)
    return ks,ns,vx,vy,vz,bx,by,bz

